package com.pai4j.ugc.repository.dao;


import com.pai4j.ugc.repository.entity.MomentEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import java.util.Date;


@Repository
public interface IMomentDAO  extends JpaSpecificationExecutor<MomentEntity>,
        JpaRepository<MomentEntity, Long> {


    /**
     * 根据动态id查询作者id
     * @param resourceId 动态id
     * @return
     */
    String findAuthorIdById(Long resourceId);

    /**
     * 根据作者查询动态
     * @param author 作者
     * @param pageable 分页参数
     * @return
     */
    Page<MomentEntity> findByAuthor(String author, Pageable pageable);

    /**
     * 查询近afterDate创建的动态，按ID倒序分页
     */
    Page<MomentEntity> findByCreateDateAfter(Date afterDate, Pageable pageable);

    /**
     * 基于ID倒序的游标分页：查询ID小于lastId的动态，按ID倒序分页
     */
    Page<MomentEntity> findByIdLessThanOrderByIdDesc(Long lastId, Pageable pageable);
}
